<?php

/**
 * This is the model class for table "catalog_category".
 *
 * The followings are the available columns in table 'catalog_category':
 * @property string $id
 * @property string $seo_id
 * @property string $name_id
 * @property string $text_id
 * @property string $parent_id
 * @property integer $active
 */
class CatalogCategory extends AActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return CatalogCategory the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'catalog_category';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('seo_id, name_id, text_id, active', 'required'),
			array('active', 'numerical', 'integerOnly'=>true),
			array('seo_id, name_id, text_id, parent_id', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, seo_id, name_id, text_id, parent_id, active', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'seo' => array(self::BELONGS_TO, 'Seo', 'seo_id'),
			'name' => array(self::BELONGS_TO, 'Text', 'name_id'),
			'text' => array(self::BELONGS_TO, 'Text', 'text_id'),
			'parent' => array(self::BELONGS_TO, 'CatalogCategory', 'parent_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'seo_id' => 'Seo',
			'name_id' => 'Заголовок',
			'text_id' => 'Описание',
			'parent_id' => 'Родитель',
			'active' => 'Активность',
			'seo'=>'Seo',
			'name'=>'Заголоаок',
			'text'=>'Описание',
			'parent'=>'Родитель',
			'name.string'=>'Заголовок',
			'parent.name.string'=>'Родитель',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('seo_id',$this->seo_id,true);
		$criteria->compare('name_id',$this->name_id,true);
		$criteria->compare('text_id',$this->text_id,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	public function getDeleteConfig(){
		return array(
			'seo',
			'name',
			'text',
		);
	}
}